//
//  JudgesCommentView.m
//  VideoExam
//
//  Created by apple on 2020/4/23.
//

#import "JudgesCommentView.h"
@interface JudgesCommentView ()
@property(nonatomic,strong)UIView * baseView;
@property(nonatomic,strong)UIImageView * showImageView;
@property(nonatomic,strong)UILabel * nameLabel;
@property(nonatomic,strong)UILabel * showTitleLabel;
@property(nonatomic,strong)UILabel * showSubTitleLabel;
@property(nonatomic,strong)UILabel * contentLabel;
@property(nonatomic,strong)OrderDetailsModel * model;
@end
@implementation JudgesCommentView

- (instancetype)initWithFrame:(CGRect)frame model:(nonnull OrderDetailsModel *)model {
    self = [super initWithFrame:frame];
    if (self) {
        self.model=model;
        [self uiSet];
    }
    return self;
}
- (void)dismisClicked {
    [self removeFromSuperview];
}
- (void)uiSet {
    
    self.backgroundColor = RGBA(0, 0, 0, 0.45);
    
    self.baseView = [[UIView alloc] initWithFrame:CGRectZero];
    self.baseView.backgroundColor=[UIColor whiteColor];
    self.baseView.layer.cornerRadius=12;
    self.baseView.layer.masksToBounds=YES;
    [self addSubview:self.baseView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(self.mas_right).offset(-15);
        make.height.mas_equalTo(115);
    }];
    
    self.showImageView =[UIFactory create_ImageView_ImageName:@"icon_默认头像_70_nor"];
    [self.showImageView sd_setImageWithURL:[NSURL URLWithString:self.model.pictureUrl] placeholderImage:UIImageMake(@"icon_默认头像_70_nor")];
    self.showImageView.layer.cornerRadius = 30;
    self.showImageView.layer.masksToBounds = YES;
    [self.baseView addSubview:self.showImageView];
    [self.showImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(12);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    ///评委名
    self.nameLabel = [UIFactory create_LabelContent:self.model.name textColor:nil fontSize:17];
    self.nameLabel .font=[UIFont boldSystemFontOfSize:17];
    [self.baseView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.showImageView.mas_right).offset(12);
        make.top.mas_equalTo(17);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(24);
    }];
    //考级委员会
    self.showTitleLabel = [UIFactory create_LabelContent:self.model.committeeName textColor:color(@"#40000000") fontSize:14];
    self.showTitleLabel .font=[UIFont boldSystemFontOfSize:14];
    self.showTitleLabel.adjustsFontSizeToFitWidth = YES;
    [self.baseView addSubview:self.showTitleLabel];
    [self.showTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(19);
        make.left.mas_equalTo(self.nameLabel.mas_right).offset(5);
        make.right.mas_equalTo(self.baseView.mas_right).offset(-12);
        make.height.mas_equalTo(20);
    }];
    
    NSString *str = [NSString stringWithFormat:@"评审资质编号：%@",self.model.qualificationCode];
    CGFloat width = [self get_width_content:str];
    self.showSubTitleLabel = [UIFactory create_LabelContent:str textColor:color(@"#DBA738") fontSize:12];
    self.showSubTitleLabel.backgroundColor=RGBA(255, 251, 237, 1);
    self.showSubTitleLabel.layer.cornerRadius=9;
    self.showSubTitleLabel.layer.borderColor=[color(@"#DBA738") CGColor];
    self.showSubTitleLabel.layer.borderWidth=1;
    self.showSubTitleLabel.layer.masksToBounds=YES;
    self.showSubTitleLabel.textAlignment = NSTextAlignmentCenter;
    [self.baseView addSubview:self.showSubTitleLabel];
    [self.showSubTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(7);
        make.left.mas_equalTo(self.showImageView.mas_right).offset(5);
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(18);
    }];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectZero];
    line.backgroundColor = color(@"#F0F0F0");
    [self.baseView addSubview:line ];
    [line  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.showImageView.mas_bottom).offset(12.5);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    //评委点评
    self.contentLabel = [UIFactory create_LabelContent:self.model.reviews textColor:color(@"#A6000000") fontSize:16];
    self.contentLabel .numberOfLines=0;
    [self.baseView addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(line.mas_bottom).offset(12);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(self.baseView.mas_right).offset(-15);
    }];
    [self layoutIfNeeded];
    CGFloat height =self.contentLabel.bottom+15;
    [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(height);
        make.center.mas_equalTo(self);
    }];
    
    UIButton * btn = [UIFactory create_btnWithTitle:@"" imageName:@"24_nor" backgroundColor:nil TypefaceColor:[UIColor blackColor] fontSize:12 target:self action:@selector(dismisClicked)];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.baseView.mas_bottom).offset(20);
        make.centerX.mas_equalTo(self.baseView);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
  
    
}
- (CGFloat)get_width_content:(NSString *)content {
    UILabel * label = [UIFactory create_LabelContent:content textColor:[UIColor whiteColor] fontSize:12];
    label.frame = CGRectMake(0, 0, SCREEN_WIDTH, 20);
    CGSize size = [label sizeThatFits:label.frame.size];
    return size.width + 20;
}

+ (void)show_model:(OrderDetailsModel *)model {
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    JudgesCommentView *selfView = [[JudgesCommentView alloc] initWithFrame:window.bounds model:model];
    [window addSubview:selfView];
}
@end
